import request from './request'

// 医生信息接口类型定义
export interface DoctorInfo {
  doctorId: number
  doctorName: string
  imagePic: string
  jobTitle: string
  inauguralHospital: string
  praise: number
  serverNum: number
  servicePrice: number
  followFlag: number
  personalProfile: string
  goodField: string
  commentNum: number
  praiseNum: number
  badNum: number
  doctorReceiveGiftList: DoctorGift[]
  commentList: DoctorComment[]
}

export interface DoctorGift {
  worth: number
  receiveNum: number
  giftPic: string
  giftName: string
  meaning: string
}

export interface DoctorComment {
  nickName: string
  headPic: string
  content: string
  commentTime: number
}

export interface DoctorInfoResponse {
  status: string
  message: string
  result: DoctorInfo
}

/**
 * 查询医生明细信息
 * @param doctorId 医生ID
 * @returns Promise<DoctorInfoResponse>
 */
export const getDoctorInfo = (doctorId: number): Promise<DoctorInfoResponse> => {
  return request.get('/health/user/inquiry/v1/findDoctorInfo', {
    params: { doctorId }
  }).then(res => res.data)
}

export interface FollowDoctorResponse {
  status: string
  message: string
}

/**
 * 关注医生
 * @param doctorId 医生ID
 * @returns Promise<FollowDoctorResponse>
 */
export const followDoctor = (doctorId: number): Promise<FollowDoctorResponse> => {
  return request.post('/health/user/inquiry/verify/v1/followDoctor', {
    doctorId
  }).then(res => res.data)
}

/**
 * 取消关注医生
 * @param doctorId 医生ID
 * @returns Promise<FollowDoctorResponse>
 */
export const cancelFollowDoctor = (doctorId: number): Promise<FollowDoctorResponse> => {
  return request.delete('/health/user/inquiry/verify/v1/cancelFollow', {
    params: { doctorId }
  }).then(res => res.data)
}

export interface ConsultDoctorResponse {
  status: string
  message: string
  doctorUserName: string
}

/**
 * 咨询医生
 * @param doctorId 医生ID
 * @returns Promise<ConsultDoctorResponse>
 */
export const consultDoctor = (doctorId: number): Promise<ConsultDoctorResponse> => {
  return request.put('/health/user/inquiry/verify/v1/consultDoctor', null, {
    params: { doctorId }
  }).then(res => res.data)
}

// 用户关注的医生列表
export interface FollowedDoctorItem {
  id: number
  doctorId: number
  name: string
  imagePic: string
  jobTitle: string
  inauguralHospital: string
  departmentId: number
  departmentName: string
  praiseNum: number
  badNum: number
  number: number
}

export interface FollowedDoctorListResponse {
  status: string
  message: string
  result: FollowedDoctorItem[]
}

export const getFollowedDoctorList = (page: number = 1, count: number = 10): Promise<FollowedDoctorListResponse> => {
  return request.get('/health/user/verify/v1/findUserDoctorFollowList', {
    params: { page, count }
  }).then(res => res.data)
}

